import time

import requests
import json
# 上传文件的接口URL
upload_url = 'http://81.70.145.220:7861/ai/knowledge_base/upload_docs'

# 设置要上传的文件的路径
file_path = 'D:\\item\\langchainDemo\\charomaDb\\data\\paul_graham\\page_3.txt'

# 设置文件的表单字段名和其他参数
knowledge_base_name = '301'
to_vector_store = True
override = False
not_refresh_vs_cache = False
chunk_size = 1024
chunk_overlap = 50
zh_title_enhance = False
docs = {
    "test.txt": [
        {
            "page_content": "custom doc",
            "metadata": {},
            "type": "Document"
        }
    ]
}

# 打开文件
with open(file_path, 'rb') as file:
    files = {
        'files': (file.name, file),
    }
    data = {
        'knowledge_base_name': knowledge_base_name,
        'to_vector_store': to_vector_store,
        'override': override,
        'not_refresh_vs_cache': not_refresh_vs_cache,
        'chunk_size': chunk_size,
        'chunk_overlap': chunk_overlap,
        'zh_title_enhance': zh_title_enhance,
        'docs': json.dumps(docs),
    }
    start_time=time.time()
    # 发送POST请求，files参数是包含文件数据的字典，data参数是包含其他表单数据的字典
    response = requests.post(upload_url, files=files, data=data)
    end_time = time.time()

# 打印响应内容
print(response.text)
print(end_time-start_time)